#coding=utf-8
from django.shortcuts import render
from django.http import HttpResponse
from models import Users,Lessons,Teacherlesson
from django.conf import settings
import os
def order(request):
	if 'id' in request.session:
		u=Users.objects.filter(id=int(request.session["id"]))
		context={"user":u[0]}
		return render(request,"order.html",context)
	return render(request,"login.html")

def order_stu(request):
	if 'id' in request.session:
		u=Users.objects.filter(id=int(request.session["id"]))
		context={"user":u[0]}
		return render(request,"order_stu.html",context)
	return render(request,"login.html")

def order_tea(request):
	if 'id' in request.session:
		u=Users.objects.filter(id=int(request.session["id"]))
		context={}
		context['user']=u[0]
		lessonlist=Lessons.objects.filter(status=0)
		context["lessonlist"]=lessonlist
		return render(request,"order_tea.html",context)
	return render(request,"login.html")

def receiver_order(request):
	lessonid = request.POST['lessonid']
	lesson=Lessons.objects.filter(id=lessonid)[0]
	lesson.status=1
	lesson.save()
	teacheerlesson=Teacherlesson(users_id=request.session["id"],lessons_id=lesson.id,status=0,title=lesson.title,request=lesson.request)
	teacheerlesson.save()
	return HttpResponse("OK")
	pass

def order_sub(request):
	if 'id' in request.session:
		u=Users.objects.filter(id=int(request.session["id"]))
		title=request.POST['title']
		content=request.POST['content']
		lessons=Lessons(users_id=request.session["id"],title=title,request=content,status=0)
		lessons.save()
		context={"user":u[0]}
		return render(request,"myinfo.html",context)
	return render(request,"login.html")